var t = require("../../api.js"), a = getApp();

Page({
    data: {
        order: null,
        getGoodsTotalPrice: function() {
            return this.data.order.total_price;
        },
        dis_order: null,
        order_id: 0
    },
    onLoad: function(e) {
        a.pageOnLoad(this, e);
        this.getOrder(e.id);
        
    },
    getOrderINfo () {
      var o = this;
        o.setData({
            store: wx.getStorageSync("store")
        }), wx.showLoading({
            title: "正在加载"
        }), a.request({
            url: t.order.detail,
            data: {
                order_id: o.data.dis_order.order_id,
                is_dis: 1
            },
            success: function(t) {
                0 == t.code && o.setData({
                    order: t.data
                });
            },
            complete: function() {
                wx.hideLoading();
              o.shouhou_time()
            }
        });
    },
    copyText: function(t) {
        var a = t.currentTarget.dataset.text;
        wx.setClipboardData({
            data: a,
            success: function() {
                wx.showToast({
                    title: "已复制"
                });
            }
        });
    },
    location: function() {
        var t = this.data.order.shop;
        wx.openLocation({
            latitude: parseFloat(t.latitude),
            longitude: parseFloat(t.longitude),
            address: t.address,
            name: t.name
        });
    },
  shouhou_time: function (a) {
    var that = this;
    var orders = this.data.order;
    orders.after_time = orders.after_time-1;
    that.setData({
      order:orders
    })
    if(orders.after_time>0){
      setTimeout(that.shouhou_time, 1000);
    }
  
  },
  getOrder: function (id) {
    var o = this;
    a.request({
      url: t.distributor.order_info,
      data: {
          id: id
      },
      success: function(t) {
          0 == t.code && o.setData({
              dis_order: t.data,
          },function () {
            o.getOrderINfo()
          });
      },
      complete: function() {

      }
    })
  },
  daohang: function (t) {
    var name = t.currentTarget.dataset.name,
    longitude = t.currentTarget.dataset.longitude,
    latitude = t.currentTarget.dataset.latitude;
    wx.openLocation({
      latitude:parseFloat(latitude),
      longitude: parseFloat(longitude),
      name: name
    })
  }
    
});